import anime from 'animejs'

//旋转特效
export const rotateAnimate = function (targets, duration, autoplay, loop) {
    return anime({
        targets: targets,
        rotate: 360,
        duration: duration,//动作执行时间
        autoplay: autoplay,//是否自动开启动作
        easing: 'linear',
        loop: loop//动作是否开启循环
    });
}
//闪烁特效
export const scaleAnimate = function (targets, duration, autoplay, loop) {
    return anime({
        targets: targets,
        scale: [0.7, 1, 1.3, 1],
        duration: duration,//动作执行时间
        autoplay: autoplay,//是否自动开启动作
        easing: 'linear',
        loop: loop//动作是否开启循环
    });
}
//滑动特效
export const translateAnimate = function (targets, translates, duration, autoplay, loop) {
    if (!translates) {
        translates = [
            {translateY: -40},
            {translateX: 250},
            {translateY: 40},
            {translateX: 0},
            {translateY: 0}
        ]
    }
    return anime({
        targets: targets,
        keyframes: translates,
        duration: duration,//动作执行时间
        autoplay: autoplay,//是否自动开启动作
        easing: 'linear',
        loop: loop//动作是否开启循环
    });
}
//显隐、旋转、闪烁、滑动特效,display:block、none
export const Animate = function (targets, display, rotate, scale, translates, duration, autoplay, loop) {
    return anime({
        targets: targets,
        display: display,
        rotate: rotate,
        scale: scale,
        keyframes: translates,
        duration: duration,//动作执行时间
        autoplay: autoplay,//是否自动开启动作
        easing: 'linear',
        loop: loop//动作是否开启循环
    });
}
//删除特效
export const removeAnimate = function (targets) {
    anime.remove(targets)
}
//获取当前特效的实例组
export const getAnimateArray = function () {
    console.log('当前特效', anime.running);
}
//获取当前特效的实例
export const getAnimate = function () {
    return anime;
}
